package com.tul.exercise.base.thread.base;

/**
 * 一个简单的任务，实现Runnable接口
 */
public class LightOff implements Runnable {
    /**
     * 计数器
     */
    protected int countDown = 10;

    private static int taskCount = 0;

    /**
     * 任务编号
     */
    private final int id = ++taskCount;

    public LightOff() {

    }

    public LightOff(int countdown) {
        this.countDown = countdown;
    }

    public String status() {
        return "#" + id + "(" + (countDown > 0 ? countDown : "Light Off") + "),";
    }

    @Override
    public void run() {
        while (countDown-- >0) {
            System.out.println(status());

            // 暂停当前线程，执行其他线程
            Thread.yield();
        }

    }
}
